package com.icart.repositories;


import com.icart.entities.CuCustinfoEntity;
import org.springframework.context.annotation.Scope;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Scope("prototype")
public interface CustinfoRepository extends BaseRepository<CuCustinfoEntity,Integer> {
    /*登录*/
    @Query(nativeQuery = true,value = "select * from cu_custinfo where mobile=?1 LIMIT 0,1")
     CuCustinfoEntity login(String mobile);

    /*登录是判断有没有openid*/
    @Query(nativeQuery = true,value = "select * from cu_custinfo where wxid=?1 LIMIT 0,1")
    CuCustinfoEntity loginfindopenid(String openid);

    /*注册*/
    @Transactional
    @Query(nativeQuery = true,value = "insert into cu_custinfo(mobile,wxid) values(?1,?2) ")
    @Modifying(clearAutomatically = true)
    Integer register(String mobile,String wxid);

    /*输入真实姓名ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set custname=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer savecustname(String custname,Long custid);

    /*输入电话ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set mobile=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer savemobile(String mobile,Long custid);

    /*输入性别ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set fm=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer savesex(String fm,Long custid);

    /*输入客户信息ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set custbirthday=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer savecustbirthday(String custbirthday,Long custid);

    /*输入Email ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set email=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer saveemail(String custbirthday,Long custid);

    /*输入月收入 ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set income=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer saveincome(String income,Long custid);

    /*输入身份证号ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set idnum=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer saveidnum(String idnum,Long custid);

    /*输入地址ajax存储*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set addr=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer saveaddr(String addr,Long custid);

    /*绑定微信号*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set wxid=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer savewxid(String openid,Long custid);

    /*绑解绑微信号*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set wxid='' where custid=?1")
    @Modifying(clearAutomatically = true)
    Integer delwxid(Long custid);

    /*返回行驶证信息，就修改用户名*/
    @Transactional
    @Query(nativeQuery = true,value = "update cu_custinfo set custname=?1 where custid=?2")
    @Modifying(clearAutomatically = true)
    Integer updatecustname(String custname,Long custid);
}

